﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Network;

namespace GameProcess.Actors
{
    class RotationsActor : IActor, IPacketHandler
    {
        GameState _gameState;

        public RotationsActor(GameState gameState)
        {
            this._gameState = gameState;
        }

        public void UpdateClient(GameTime gameTime)
        {
            _gameState.NetPlayer.ClientPacket.PlayerAngle = _gameState.Player.Angle;
        }

        public void UpdateServer(GameTime gameTime)
        {
            // ничего не нужно делать
        }

        public void ReceiveClient(ServerPacket msg)
        {
            foreach (var item in msg.PlayersAngles)
            {
                _gameState.Players[item.Key].Angle = item.Value;
            }
        }

        public void ReceiveServer(ClientPacket msg)
        {
            _gameState.Players[msg.PlayerId].Angle = msg.PlayerAngle;
            foreach (var netPlayer in _gameState.NetPlayers.Values)
            {
                netPlayer.ServerPacket.PlayersAngles[msg.PlayerId] = msg.PlayerAngle;
            }
        }
    }
}
